package com.fjec.market.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fjec.common.util.DateUtil;
import com.fjec.common.view.ServiceProjectVO;
import com.fjec.market.entity.InfoServiceProject;
import com.fjec.market.mapper.InfoServiceProjectMapper;
import com.fjec.market.service.IInfoServiceProjectService;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * <p>
 * 003.服务项目表（包括礼物） 服务实现类
 * </p>
 *
 * @author admin
 * @since 2020-09-18
 */
@Service
public class InfoServiceProjectServiceImpl extends ServiceImpl<InfoServiceProjectMapper, InfoServiceProject> implements IInfoServiceProjectService {

    @Resource
    private InfoServiceProjectMapper mapper;

    @Override
    public Map<String, ServiceProjectVO> getServiceProjectByIds(String giftIds) throws Exception {
        String[] strGiftIds = giftIds.split(",");
        List<InfoServiceProject> entityList = mapper.selectBatchIds(Arrays.asList(strGiftIds));
        Map<String, ServiceProjectVO> resultMap = new HashMap<>();
        for (InfoServiceProject entity : entityList) {
            ServiceProjectVO view = new ServiceProjectVO();
            BeanUtils.copyProperties(view, entity);
            view.setStrCreateTime(DateUtil.format(entity.getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
            if (entity.getUpdateTime() != null) {
                view.setStrUpdateTime(DateUtil.format(entity.getUpdateTime(), "yyyy-MM-dd HH:mm:ss"));
            } else {
                view.setStrUpdateTime("");
            }
            resultMap.put(entity.getId().toString() ,view);
        }
        return resultMap;
    }
}
